#ifndef _PTM_FRAME_FIFO_
#define _PTM_FRAME_FIFO_

#include "fifo_buf.h"
#include "media_frame_hd.h"

#include <list>
#include <vector>

using namespace std;


typedef struct _CUSTOMER_INFO_
{
	int      clientID; //
	uint32_t consumePos;
	bool     bConver;
	int64_t  pts;
}CUSTOMER_INFO;
// ��Ҫ��ר����¼��ʹ��
class CFIFO_PTMFrame : public CFIFO_buf
{
public:
	CFIFO_PTMFrame();
	~CFIFO_PTMFrame();
	int     Open(int bufSize, int oneframe_sz, int channel);
	int     OpenReader(int clientID);
	int     CloseReader(int clientID);
	int		WriteFrame(uchar_t* buf, uint32_t size, int frameType, int64_t pts = 0, int codeType = 0);// , bool cycleMode = true);
	int		WriteAudioFrame(uchar_t* buf, uint32_t size);
	int     ReadFrame(uchar_t* buf, int size, int clientID);
	int     ReadFrameNewest(uchar_t* buf, int size, int delay, int clientID);
	int     SeekTime(int64_t startTime, int prepareSecs, int clientID = 0);
	int     GetDataSizeByTime(int64_t time, int prepareSecs);
	int		GetWriteBufAddr(uint32_t data_size, FIFO_BUF_INFO* bufInfo);

	int		GetFrameBufAddr(FIFO_BUF_INFO* bufInfo, int clientID);
	int		ConsumeFrame(int frm_sz, int clientID);
	int		GetFrameSize(int clientID);
	int		FreeFrameSpace(uint32_t dataSize);
	int     GetDataWater(int clientID);
	uint32_t GetDataSize(int clientID);
	void	SetRate(int frmRate)
	{
		m_frmHead.frameRate = frmRate;
	}
	void SetEncSvcSpeed(int svc_speed)
	{
		m_frmHead.enc_svc_speed = svc_speed;
	}
public://inline
	typedef struct _CACHE_FRM_INFO_
	{
		int64_t   time;
		uint32_t  pos;
		uint32_t  frmNo;
		uint32_t  len;
		uint8_t   frameType;	//����������
	}CACHE_FRM_INFO;
	int GetStartTime(int64_t& startTIme)
	{
		if (m_lstFrm.size())
		{
			startTIme = m_lstFrm.begin()->time;
			return 0;
		}
		else
		{
			return ERR_PARAM;
		}
	}

	int close();
	int Reset();
	int64_t	GetEndTime()
	{
		return m_lastTime;
	}

	list<CACHE_FRM_INFO>* GetFrmList()
	{
		return &m_lstFrm;
	}

	static const int FRAME_H_LEN = BASE_FRAME_HEAD_LEN;
protected:

	int				m_ch;			//��Ƶͨ��
	int64_t			m_lastTime;     //Ԥ¼�����һ����ʱ��
	RD_FRAME_H      m_frmHead;		//��Ƶ֡ͷ
	int				m_IFrmDiffSize;	//I֡��������ݲ�
	list<CACHE_FRM_INFO> m_lstFrm;
	uchar_t* m_alignBuf;		//ר�ô������ݷֶΣ���Ҫ���ƵĻ��森
	uchar_t			m_audioAlignBuf[160]; //
	int             m_audioCacheSize;
	int             m_alignSz;
	int				m_alignIdx;

	uint32_t        m_frameNo;
	uint32_t        m_frmaeNoAudio;
	uint32_t        m_readFrameNo;	//����ȡ�ı��
	vector<CUSTOMER_INFO> m_vecCustmer;	//��������Ϣ����
	bool            m_bCover;		//�Ƿ�ѭ��д��
};

#endif //_PTM_FRAME_FIFO_
